package com.jl.cloud.commom.config;


import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * xxl-job注入配置
 * @author liang.jun
 */
@Configuration
@ConditionalOnExpression("${config.xxljob.enabled:false}")
@Slf4j
public class XxlJobConfig {


    @Value("${xxl-job.adminAddresses}")
    private String adminAddresses;

    @Value("${spring.application.name}")
    private String appName;


    @Value("${xxl-job.port}")
    private int port ;

    @Value("${xxl-job.logPath}")
    private String logPath ;

    @Value("${xxl-job.logRetentionDays}")
    private int logRetentionDays;

    @Value("${xxl-job.accessToken}")
    private String accessToken;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appName);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        log.info(">>>>>>>>>>>>>>>> xxl-job config adminAddresses {} ,appName {} , port {} ,logPath {} ,logRetentionDays {} ",adminAddresses,appName,port,logPath,logRetentionDays);
        return xxlJobSpringExecutor;
    }


}
